<?php
require_once '../include/common.inc.php';

$sql = "SELECT po.*,pi.firstname,pi.lastname FROM  promoter_order po,promoter_info pi where po.promoter_id=pi.id  order by po.date desc";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $out_ary[] = $rs;
}

for($i=0;$i<count($out_ary);$i++)
{

if($out_ary[$i]['card_type']=="V-DK")$out_ary[$i]['new_id']=$out_ary[$i]['id']."<font color=red>*</font>";
else $out_ary[$i]['new_id']=$out_ary[$i]['id'];

$out_ary[$i]['date']=date('Y-m-d',$out_ary[$i]['date']);

//$sql = "SELECT * FROM  promoter_info  where id=".$out_ary[$i]['promoter_id'];
//$query = $db->query($sql);
//$rs = $db->fetch_array($query);
$out_ary[$i]['promoter']=$out_ary[$i]['promoter_id']."/".$out_ary['firstname'].$out_ary['lastname'];

$out_ary[$i]['cost']=number_format($out_ary[$i]['cost'],2);

if($out_ary[$i]['deliver_status']==0)$out_ary[$i]['deliver_status']="Non-deliver";
elseif($out_ary[$i]['deliver_status']==1) $out_ary[$i]['deliver_status']="Delivered";
else $out_ary[$i]['deliver_status']="Cancelled";
}



header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=Order_Info_" . date("Ymd") . ".xls");  

echo "Order No \t";
echo "Order Date \t";
echo "Promoter ID Name\t";
echo "Order Amount\t";
echo "Pay amount\t";
echo "Deliver Status\t\n";


for ($i=0;$i<count($out_ary);$i++){

echo replaceHtmlAndJs($out_ary[$i]['id']  ). "\t"; 
echo replaceHtmlAndJs($out_ary[$i]['date']  ). "\t"; 
echo replaceHtmlAndJs($out_ary[$i]['promoter'] ). "\t"; 
echo replaceHtmlAndJs($out_ary[$i]['cost']  ). "\t"; 
echo replaceHtmlAndJs($out_ary[$i]['pay_amount'] ). "\t"; 
echo replaceHtmlAndJs($out_ary[$i]['deliver_status'] ). "\t"; 

echo "\n"; 
}
?>

